package com.xiaoy.core.database.entity;

import javax.transaction.SystemException;


public class Column {

	private String name = "";
//	private DataTableColumnType type;
	private String type;
	private String isNull = "Y";
	private String defaultValue = "";
	private String length = "";
	
	private String info ;
	
	public Column (){}
	
	public Column (String name,String type) {
		
		this.name = name;
		this.type = type;
	}
	public Column (String name,String type,String length){
		this(name,type);
		this.length = length;
	}
	public Column (String name,String type,String length,String isNull,String defaultValue){
		this(name,type,length);
		this.isNull=isNull;
		this.defaultValue=defaultValue;
	}
	
	public String getLength() {
		return length;
	}

	public void setLength(String length) {
		this.length = length;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getDefaultValue() {
		return defaultValue;
	}
	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}
	
	public String getIsNull() {
		return isNull;
	}

	public void setIsNull(String isNull) {
		this.isNull = isNull;
	}

	public String toString () {
		
		String isn = "";
		if (!"".equals(isNull)) {
			isn = "not null";
		}
		
		String trim = "";
		if (defaultValue != null) {
			trim= defaultValue.trim();
			if (trim.length()>0) {
				trim = trim.replaceAll("'", "''");
				trim = "default '"+trim+"'";
			}
		}
		
		String len = "";
		
		if (type == DataTableColumnType.DATE) {
			return name+"    "+type+"    "+trim+"    "+isn;
		}else if (length==null||"".equals(length)) {
			len = DataTableColumnType.getDefaultLenth(type);
		}else {
			len = length;
		}
		
		return name+"    "+type+"("+len+")    "+trim+"    "+isn;
	}
	
	public static void main(String[] args) throws SystemException {
//		try {
//		}catch (Exception e) {
//			throw new SystemException("ssss");
//		}
//		DataTableColumnType type = DataTableColumnType.DATE;
//		System.out.println((type == DataTableColumnType.DATE)+"   "+type.equals(DataTableColumnType.DATE));
			
		
	}
}
